// graceUI/components/graceTree.js
Component({
  properties: {
    trees : {type:Array, value:function () {return [];}},
		indent : {type:Number, value:28},
		level  : {type:Number, value:0},
		lineHeight  : {type:String, value:'80rpx'},
		fontSize  : {type:String, value:'28rpx'},
		fontColor : {type:String, value:'#323232'},
		type : {type:String, value:'text'},
		isIcon : {type:Boolean, value:true},
		iconSize:{type:String, value:'30rpx'},
		indexes : {type:Array, value:['',0]},
		checkedId : {type:[String, Number], value:'-1'},
		checkedIds : {type:Array, value: []},
		checkedColor:{type:String, value:'#3688FF'},
		allCanCheck: {type:Boolean, value:true},
		isFold : {type:Boolean, value:true}
  },
  data: {
    treesIN:[],
		indexesIn : [],
		fold:false
  },
  ready:function(){
    this.setData({treesIN : this.data.trees});
		if(this.data.indexes[0] != ''){
			var indexes  =  this.data.indexes[0].split(',');
		}else{
			var indexes = [];
		}
		indexes.push(this.data.indexes[1]);
    this.data.indexesIn = indexes.join(',');
    this.setData({indexesIn : this.data.indexesIn});
  },
  methods: {
    taped : function(e){
			var havsons       = e.currentTarget.dataset.havsons;
			var treeindexs = e.currentTarget.dataset.treeindexs;
			treeindexs = treeindexs.split(',');
			var index      = e.currentTarget.dataset.index;
			treeindexs.push(index);
			treeindexs.shift();
			if(this.data.type == 'text'){
				if(this.data.isFold){
					if(havsons){this.setData({fold : !this.data.fold}); return;}
				}
				this.tapbase(treeindexs);
			}else{
				var cancheck = e.currentTarget.dataset.cancheck;
				if(cancheck){this.tapbase(treeindexs);}
			}
			
		},
		tapbase : function(e){
      if(e.detail){e = e.detail;}
			this.triggerEvent('taped', e);
		},
		setTrees : function (trees) {
      this.setData({treesIN : trees});
		}
  }
})
